﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace Conusic
{
    public static class PiterMoskvaFm
    {
        private const string ParseRegexTop = @"class=""song"">([^<]*)</a>.{0,512}?class=""artist"">([^<]*)</a>";

        public static List<AudioRecord> GetTop100PiterFm()
        {
            string page = SimpleHttp.RequestPage(@"http://www.piter.fm/charts/top100");

            var result = ParsePiterMoskvaFmTopPage(page);
            return result;
        }

        private static List<AudioRecord> ParsePiterMoskvaFmTopPage(string page)
        {
            var result = new List<AudioRecord>(100);

            foreach (Match match in Regex.Matches(page, ParseRegexTop, RegexOptions.Singleline))
            {
                result.Add(new AudioRecord(match.Groups[1].ToString(), match.Groups[2].ToString()));
            }
            return result;
        }
    }
}